<#include "../common/common.html"/> <@layout>
<script
        src='${ctx}/static/inc/platform/js/jQuery/jquery.ztree.core-3.5.min.js'
        type='text/javascript'></script>
<link href='${ctx}/static/inc/platform/css/zTreeStyle.css'
      type='text/css' rel='stylesheet'>
<script
        src='${ctx}/static/inc/platform/js/jQuery/jquery.ztree.excheck-3.5.min.js'
        type='text/javascript'></script>

<body class="easyui-layout">
<body class="easyui-layout"  fit='true'>>
<div region="west" split="true" title="代码列表" style="width:200px;padding:1px;">
    <div id="tt" style="overflow: auto;">
        <ul id="ztree" class="ztree"></ul>
    </div>
</div>
<div region="center" id="content" title=" ">
    <iframe src="" name="ifrm" id="ifrm" width="100%" height="100%" scrolling="auto" border="0" frameborder="0"></iframe>
</div>

</body>

<script type="text/javascript">
    function show(url) {
        document.getElementById('ifrm').src=url;

    }
    var treeObj;

    $(function() {
        var setting = {
            async: {
                enable: true, //true 表示 开启 异步加载模式   false 表示 关闭 异步加载模式
                url:"/common/comboTree?table=codes&fields=type as id,name as name,type as pid&pid=pid&pidStart=0&id=id" ,
                autoParam:["type"],
                otherParam: ["code","" ]
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pid"

                }
            },
            callback: {
                onClick: zTreeOnClick,
                onNodeCreated: openZtreeLevel
            },
            view:{
                fontCss: getFont
            }
        };

        treeObj=$.fn.zTree.init($("#ztree"), setting);

    });
    function getFont(treeId, node) {
        return node.font ? node.font : {};
    }

    function zTreeOnClick(event, treeId, treeNode) {
        $("#content").panel({
            title:treeNode.name
        });
        var Url="/codes/trees";
        document.getElementById('ifrm').src=Url;
    }

    var _click=0;
    function openZtreeLevel(event, treeId, treeNode) {
        if(treeNode.level >= 1) {
            return;
        }
        //默认单击首个根节点，从而让右边内容不空
        if(treeNode.level==0 && _click==0) {//_click==0表示首个根节点才执行，当多个根节点时避免每个都执行click事件
            _click++;
            treeObj.selectNode(treeNode);//默认让根节点选中
            $('#ztree .curSelectedNode').trigger('click');//执行选中节点的click事件
        }
        if(treeNode.isParent == true || treeNode.isParent == 'true') {
            treeObj.expandNode(treeNode, true, false, true);
        }
    }
</script>
</@layout>
